package com.cskaoyan.service.wx;

import com.cskaoyan.Utils.MyUtils;
import com.cskaoyan.bean.goods.Goods;
import com.cskaoyan.bean.goods.GoodsExample;
import com.cskaoyan.mapper.goodsmapper.GoodsMapper;
import com.cskaoyan.mapper.usermapper.FootprintMapper;
import com.cskaoyan.vo.wx.WxFootPrintGoodsVo;
import com.cskaoyan.vo.wx.WxFootprintListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: feisl
 * @Date: 2021/5/13 16:39
 */
@Service
public class WxFootprintServiceImpl implements WxFootprintSerivice {

    @Autowired
    FootprintMapper footprintMapper;
    @Autowired
    GoodsMapper goodsMapper;

    @Override
    public WxFootprintListVo list(Integer page, Integer size) {
        Integer userId = MyUtils.getUserId();
//        List<WxFootPrintGoodsVo> wxFootPrintGoodsVoList = goodsMapper.selectByFootprint((page-1)*size,size,userId);
//        ArrayList<Integer> goodsIdList = footprintMapper.selectGoodsIdByUserId(userId,(page-1)*size,size);
//        ArrayList<Integer> id = footprintMapper.selectIdByUserId(userId,(page-1)*size,size);
        ArrayList<WxFootPrintGoodsVo> wxFootPrintGoodsVoList = footprintMapper.selectGoodsIdByUserId(userId, (page - 1) * size, size);
        WxFootprintListVo res = new WxFootprintListVo();
        //需要查找goods的brief ，picurl，name 和 retailprice
        for (WxFootPrintGoodsVo wxFootPrintGoodsVo : wxFootPrintGoodsVoList) {
            Goods goods = goodsMapper.selectByPrimaryKey(wxFootPrintGoodsVo.getGoodsId());
            wxFootPrintGoodsVo.setBrief(goods.getBrief());
            wxFootPrintGoodsVo.setPicUrl(goods.getPicUrl());
            wxFootPrintGoodsVo.setName(goods.getName());
            wxFootPrintGoodsVo.setRetailPrice(goods.getRetailPrice());
        }


//        List<WxFootPrintGoodsVo> list = new ArrayList<>();
//        int total = 0;
//        int footprintSize = id.size();
//        for (int i = 0; i < footprintSize; i++) {
//            int goodsId = goodsIdList.get(i);
//            int tempId = id.get(i);
//            WxFootPrintGoodsVo wxFootPrintGoodsVo = goodsMapper.selectById(goodsId);
//            wxFootPrintGoodsVo.setId(tempId);
//            list.add(wxFootPrintGoodsVo);
//            total++;
//        }
//
////        for (Integer goodsId : goodsIdList) {
////            WxFootPrintGoodsVo wxFootPrintGoodsVo = goodsMapper.selectById(goodsId);
////            list.add(wxFootPrintGoodsVo);
////            total++;
////        }
        res.setFootprintList(wxFootPrintGoodsVoList);
        res.setTotalPages(wxFootPrintGoodsVoList.size());
        return res;
    }

    @Override
    public void delete(Integer id) {

        footprintMapper.updateDeleteById(id);

    }
}
